#include "gasflow.h"
#include<QtSql>
#include <string>
#include<iostream>
#include"dbutil.h"
using namespace std;
Gasflow ::Gasflow(QObject *parent):
    QObject(parent)
{}
void Gasflow::updateGasflow(QString id,QString pitot,QString velocity,QString sectional)
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery update;
    string guoluid=id.toStdString();
    string gaspitot=pitot.toStdString();
    string gasvel=velocity.toStdString();
    string gasswct=sectional.toStdString();
    string sql = "UPDATE  gas_flow set pitot_tube="+gaspitot+
            ",velocity_field="+gasvel+",sectional_area="+gasswct+" where id="+guoluid;
    const char *k = sql.c_str();
     bool success = update.exec(k);
    if(success)  {

         qDebug()<<"upadte success";
    }
    else qDebug()<< "fail";
    db.dbclose(data);
}

void  Gasflow::selectGasflowbyid(QString id)
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery query;
    string gasid=id.toStdString();
    string sql="select *from gas_flow where id="+gasid;
    const char *k = sql.c_str();
    bool success = query.exec(k);
    QVariantList list;
    if(success)  {
       query.next();
//         while(query.next()) qDebug()<<query.value().toString();
       pit=query.value(1).toString();
       velo=query.value(2).toString();
       sect=query.value(3).toString();

    }
    else qDebug()<< "fail";
db.dbclose(data);
}
QString Gasflow::getpitot()
{
    return pit;
}
QString Gasflow::getsectional()
{
    return sect;
}
QString Gasflow::getvelocity()
{
    return velo;
}
